﻿#pragma once
#include "zyCtrol.h"
#include "zyEditBox.h"
#include "zyLmageList.h"
#include "zyWidget.h"
#include "zyListBox.h"
#include "zyDialogBox.h"
#include "zyButton.h"

namespace DarkMoonUI {
	#define TVP_GLYPH 2
	#define GLPS_CLOSED 1
	#define GLPS_OPENED 2
	#define BP_PUSHBUTTON 1
	#define PBS_NORMAL 1
	#define CP_DROPDOWNBUTTON 1
	#define CBXS_NORMAL 1
	struct PropertyGrid_item {
		int State;
		std::wstring Name;
		int Type;
		int TextColor;
		int Level;
		LPARAM lParam;
		PropertyGrid_item* Parent;
		std::wstring Value;
		std::vector<PropertyGrid_item*>* Childs;
	};

	class zyPropertyGrid : public  zyCtrol
	{
	public:
		zyPropertyGrid();
		~zyPropertyGrid();
		
		static void  WINAPI zyPropertyGrid_Destroy(zyObject* obj);
		static LRESULT WINAPI zyPropertyGrid_WndProc(zyObject* obj, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL* bHandled);
		static LRESULT WINAPI zyPropertyGrid_ChildWndProc(zyObject* obj, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL* bHandle);
		BOOL 创建(HWND 参数_父窗口, const std::wstring& 参数_标题 = L"", POINT 参数_位置 = POINT{ 0, 0 }, POINT 参数_尺寸 = POINT{ 60, 120 },
			int 参数_ID = 0, int 参数_窗口风格 = 0, int 参数_扩展风格 = 0);
		BOOL 创建(zyWindow& 参数_父窗口, const std::wstring& 参数_标题 = L"", POINT 参数_位置 = POINT{ 0, 0 }, POINT 参数_尺寸 = POINT{ 60, 120 },
			int 参数_ID = 0, int 参数_窗口风格 = 0, int 参数_扩展风格 = 0);
		bool 绑定(HWND 参数_父窗口, int 参数_资源ID, bool 参数_使用默认字体);
		bool 绑定窗口句柄(HWND 参数_窗口句柄);
		PropertyGrid_item* 插入项目_分组(int 参数_索引, const std::wstring& 参数_名称, LPARAM 参数_项目数值 = -1);
		void* 插入项目_文本(int 参数_索引, PropertyGrid_item* 参数_父项目句柄, const std::wstring& 参数_名称, const std::wstring& 参数_值, LPARAM 参数_项目数值 = -1);
		void* 插入项目_长文本(int 参数_索引, PropertyGrid_item* 参数_父项目句柄, const std::wstring& 参数_名称, const std::wstring& 参数_值, LPARAM 参数_项目数值 = -1);
		//这里的参数_值是一个列表项目的当前索引，默认为：0
		PropertyGrid_item* 插入项目_列表(int 参数_索引, PropertyGrid_item* 参数_父项目句柄, const std::wstring& 参数_名称, int 参数_值 = 0, LPARAM 参数_项目数值 = -1);
		int 列表_添加项目(PropertyGrid_item* 参数_父项目句柄, const std::wstring& 参数_名称, LPARAM 参数_项目数值 = -1);



	protected:
		void OnNCDestroy();

		void _init(HWND hWnd);
		PropertyGrid_item* _InsertProperty(int index, PropertyGrid_item* parent, const std::wstring& name, int type, int state, LPARAM lParam, const std::wstring& Value);

		int LongText_BtnImport_事件_被单击(HWND hWnd, int ID);
		int LongText_BtnCancel_事件_被单击(HWND hWnd, int ID);
		int LongText_BtnOk_事件_被单击(HWND hWnd, int ID);
		int propertyItem_List_OnSelected(HWND hWnd, int ID);
		LRESULT propertyItem_list_Msg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL* bHandle);
		LRESULT propertyItem_Edit_Msg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL* bHand);
		int propertyItem_LongText_Dialog_OnCraete(zyForm* hWnd);
		int propertyItem_LongText_Dialog_OnSize(HWND hWnd, WORD cx, WORD cy);
		
		void propertyItem_DrawNameAndStringValue(HWND hWnd, HDC hdc, PropertyGrid_item* pItem, Gdiplus::Graphics* graphics, int itemSelect, RECT rc, int nameWidth,
			int stringOffset, int stringFontStyle);
		void propertyItem_DrawBackAndLine(Gdiplus::Graphics* graphics,int nameWidth, int itemSelect, RECT rc, int isGroup);
		void propertyItem_DrawExpanding(bool Open, HWND hWnd, HDC hdc,int x,int y,int w,int h);
		void propertyItem_DrawButton(HWND hWnd, HDC hdc, Gdiplus::Graphics* graphics, int type, RECT rc);
		LRESULT propertyItem_OnDraw(PropertyGrid_item* pProperty, LPARAM lParam);

		void zyPropretyGrid_ExpandChange(PropertyGrid_item* pItem, int index);
		LRESULT zyPropretyGrid_OnItemClick(HWND hWnd, int x, int y, int mouseState, BOOL* bHandle);
		void zyPropretyGrid_HideAll();
		void propertyItem_ShowList(PropertyGrid_item* pItem, int index);
		int propertyItem_ShowEdit(PropertyGrid_item* pItem, int iItem, int offsetLeft, int offsetRight);
		int propertyItem_BeginEdit(PropertyGrid_item* pProperty, int iItem);
		int propertyItem_EndEdit(HANDLE grid, HANDLE pItem, int index);
		int propertyItem_OnClick(PropertyGrid_item* pItem, int index, int isOnButton, int mouseState);



	};

}

